package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.MyBookBean;
import com.mz.ozy.bean.MyShopBean;
import com.mz.ozy.mvp.model.MyCardModel;
import com.mz.ozy.mvp.view.MyKeepContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class MyKeepPresenter extends BasePresenterImpl<MyKeepContract.View> implements MyKeepContract.Presenter {

    private MyCardModel mModel;


    public MyKeepPresenter() {
        mModel = new MyCardModel();
    }


    @Override
    public void getBook(Activity activity, String page) {
        mModel.getBook(activity, page)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MyBookBean>(mView) {
                    @Override
                    public void onSuccesss(MyBookBean bean) {
                        mView.getBookSuccess(bean);
                    }
                });
    }

    @Override
    public void getShop(Context context, String page) {
        mModel.getShop(context, page)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MyShopBean>(mView) {
                    @Override
                    public void onSuccesss(MyShopBean bean) {
                        mView.getShopSuccess(bean);
                    }
                });
    }

    @Override
    public void getCancl(Context context, String type, String cid) {
        mModel.getCanclKeep(context, type,cid)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject bean) {
                        mView.getCanclSuccess(bean);
                    }
                });
    }
}
